var arr = [1, 3, 5, 6, 4, 2, 5, 8, 1, 2, 7, 9];

function quickSort(arr) {
  if (!arr || arr.length <= 1) {
    return arr;
  }
  var left = [];
  var right = [];
  var pivot = arr[0];

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] < pivot) {
      left.push(arr[i]);
    } else {
      right.push(arr[i]);
    }
  }

  return [...quickSort(left), pivot, ...quickSort(right)];
}

console.log(quickSort(arr));
